package com.winit.service.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.alibaba.dubbo.rpc.RpcContext;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer{
    
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/**");

    }
    
    public static class TokenInterceptor implements HandlerInterceptor{

        public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                                 Object handler) throws Exception {
            RpcContext.getContext().setAttachment("key", "asdfasdfadsfadsf");
            System.out.println("放个参数到上下文");
            return true;
        }
        
    }
}
